var id = getvl("id");
$("#zimiaoshu").html("");
$("#shangpingxiangqing").html("");
$(function () {
    if (id != '') {
        $.ajax({
            url: urlcore + "/api/user/getadmin",
            type: "get",
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            success: function (data) {
                if (data.success == true) {
                    if (usertypeuser == 2) {
                        //alert("d")
                        qiugoudata(id);
                    } else if (usertypeuser == 1) {
                        qiugoudata2(id);
                    } else {
                        qiugoudata3(id);
                    }
                } else {
                    qiugoudata3(id);
                }
            },
            error: function () {
                /* Act on the event */
									alert("error");
            }
        });
    } else {

    }
});
function qiugoudata3(id) {
    $.ajax({
        url: urlcore + "/api/wantBuy/selectOne?id=" + id,
        type: "get",
        dataType: 'json',
        contentType: "application/json;charset=utf-8",
        success: function (data) {
            if (data.success == true) {
                var da = data.data;
                var headImg2 = da.coverUrl;
                var headImg = da.goodsUrl;
                var imgStr1 = '';
                var sun = 0;
                var xiangqing = "";
                imgStr1 += `<li>
                	<a href="#"><img onerror="errorImg(this)" src=" ${headImg2} " /></a>
                	</li>`;
                xiangqing += 
				      `<div style="z-index:0;position:relative">
                	     <img  onerror="errorImg(this)" src="${headImg2}" width="400"/>
											 <div style="position:absolute; top:5%; left:190; width:100%;  height:50%;max-height:100%;text-align:center; z-index:2">
											 	<img onerror="errorImg(this)" id="logo" src="images/qiugouchenggong.png" width="400" height:'400'>
											 </div>
						</div>
					   <div></div>`;
                if (headImg != null && headImg != '') {
                    var imgarr1 = headImg.split("***");
                    $.each(imgarr1, function (index, value) {
                         
                        
                        imgStr1 += `<li style="vertical-align:middle">
                         					<a href="#"><img onerror="errorImg(this)" src="${value}"/></a>
									</li>`;
                    
						xiangqing += `<div>
							 <img style="width: 100%;" onerror="errorImg(this)" src="${value} " />
							 </div><div></div>`;
                    });

                }
                $('#img_details').html(imgStr1);
                $("#xiangqing").html(xiangqing);
                var lianxiren = "未填写";
                if (da.contactName != null) {
                    lianxiren = da.contactName;
                }
                var lianxiren2 = "尺寸未填写";
                if (da.sizeName != null) {
                    lianxiren2 = da.sizeName;
                }
                var lianxiren3 = "颜色未填写";
                if (da.colourName != null) {
                    lianxiren3 = da.colourName;
                }
                var goodsDescribe = "无描述";
                if (da.goodsDescribe != null) {
                    goodsDescribe = da.goodsDescribe;
                }
				var shangpingxiangqing=
				`<ul>
				   <li>
				     <span>发布商圈</span>
				     <em>${da.tradeAreaName}</em>
				   </li>
				   <li>
						<span>商品分类</span>
						<em>${da.wantBuyTypeName}</em>
				   </li>
				   <li>
				   	<span>联系人</span>
				   	<em>${da.user.userName}</em>
				   </li>
				   <li>
				   	<span>联系电话</span>
				   	<em>${da.phone.substr(0, 11)}</em>
				   </li>
				   <li>
				   <span>备用电话</span>
				   <em>${da.phone.substr(0, 11)}</em>
				   </li>
				   <li>
				   <span>需要数量</span>
				   <em>${da.goodsNum}件</em>
				   </li>
				   <li>
				   <span>需要地址</span>
				   <em>${da.address}</em>
				   </li>
				   <li>
				   <span>商品颜色</span>
				   <em>${lianxiren3}</em>
				   </li>
				   <li>
				   <span>商品尺码</span>
				   <em>${lianxiren2}</em>
				   </li>
				 </ul> `

                if (da.qq != null) {
                    shangpingxiangqing += '<em>' + (da.qq.substr(0, 3)) + '**** ****</em>';
                } else {
                    shangpingxiangqing += '<em></em>';

                }


                var zimiaoshu =
                    '<div class="dingdan_title">商品描述</div>' +
                    '<div class="buy_huiyuan_con">' +
                    '	<p>' + goodsDescribe + '</p>' +
                    '</div>';

//                 var zimiaoshu =
//                     `<div class="dingdan_title">商品描述</div>
//                     <div class="buy_huiyuan_con">
//                       <p> ${goodsDescribe} </p>
//                     </div>`;
                $("#zimiaoshu").append(zimiaoshu);
                $("#shangpingxiangqing").append(shangpingxiangqing);
                $(function () {
                    TouchSlide({
                        slideCell: "#slideBox",
                        titCell: ".hd ul", //开启自动分页 autoPage:true ，此时设置 titCell 为导航元素包裹层
                        mainCell: ".bd ul",
                        effect: "leftLoop",
                        autoPage: true, //自动分页
                        autoPlay: true //自动播放
                    });

                })
            } else if (data.code == 'OVERTIME') {
                var thisUrl = window.location.href;
                alert(thisUrl);
                if (thisUrl.indexOf('1.0.0denglu.html') <= -1) {
                    top.window.location.href = "1.0.0denglu.html";
                }
            } else {
                if (data.msg != '空数据') {
                    alert(data.msg)
                } else {
                    $('#thiscount').text(0);
                }
            }
        },
        error: function () {
            alert("error");
        }
    });
}
//getImg('求购成功',80);
function getImg(text, fsz) {
    var c = document.getElementById("myCanvas");
    var cxt = c.getContext("2d");
    var img = new Image();
    img.src = 'images/a_bg_hui.png';
    img.onload = function () { //图片加载完成，才可处理
        cxt.drawImage(img, 0, 0, 280, 280, 0, 0, 280, 280);
        cxt.save();
        cxt.font = fsz + "px Arial";
        cxt.textBaseline = 'middle'; //更改字号后，必须重置对齐方式，否则居中麻烦。设置文本的垂直对齐方式
        cxt.textAlign = 'center';
        var tw = cxt.measureText(text).width;
        var ftop = c.height / 2;
        var fleft = c.width / 2;
        cxt.fillStyle = "#ff0000";
        cxt.fillRect(fleft - tw / 2, ftop - fsz / 2, tw, fsz); //矩形在画布居中方式
        cxt.fillStyle = "#ffffff";
        cxt.fillText(text, fleft, ftop); //文本元素在画布居中方式
        cxt.strokeStyle = 'yellow';
        cxt.strokeText(text, fleft, ftop); //文字边框
    };

}
